package com.cskaoyan.singleton;

/**
 * 线程安全的懒加载 → 静态内部类来做
 * @author stone
 * @date 2021/12/23 10:22
 */
public class MySingleton5 {

    private static MySingleton5 mySingleton5;


    private MySingleton5(){}

    public static MySingleton5 getInstance() {
        // 懒加载 → 实例化的代码要在getInstance方法里面
        // 内部类提供一个方法让外部类能够获得其实例
        return Inner.getInnerInstance();
    }

    static class Inner{
        static {
            mySingleton5 = new MySingleton5();
        }
        public static MySingleton5 getInnerInstance() {
            return mySingleton5;
        }

    }
}
